package cz.acies.genea.ui.chart;

import java.util.ArrayList;
import java.util.List;

import cz.acies.genea.data.persist.GedFamily;
import cz.acies.genea.data.persist.GedPerson;
import cz.acies.genea.ui.svg.G2Color;
import cz.acies.genea.ui.svg.G2Line;
import cz.acies.genea.ui.svg.G2Point;
import cz.acies.genea.ui.svg.G2Rectangle;
import cz.acies.utils.UIDGenerator;

public class EmptyTreeChartNode extends TreeChartNode
{
	private static final long serialVersionUID = 748772493373568316L;
	
	public EmptyTreeChartNode() {
		super(new GedFamily(UIDGenerator.createUID("GE.F")));
	}
	
	public List<Object> rendered() throws Exception {
		compute();
		List<Object> gdata = new ArrayList<Object>();
		
		if (family != null) {
			if (leftCard == null) {
				createLeftCard(family.getMan());
			}
			leftCard.ox += (ox + 10);
			leftCard.oy += (oy + 10);
			
			List<Object> drawData = leftCard.rendered();
			gdata.addAll(drawData);
			
			double cx = (DEFAULT_WIDTH / 2) + 8;
			double cy = DEFAULT_HEIGHT / 2;
			//System.out.println("cx: " + cx + ", cy: "+cy);
			G2Rectangle rect = new G2Rectangle(ox + cx - 8, oy + cy - 8, 16, 16);
			rect.getDrawAttr().setOpacity(0);
			addGdata(gdata, rect);
			
			G2Line joinM = new G2Line(
				new G2Point(/*leftCard.ox + leftCard.x + leftCard.width*/leftCard.getRight(), rect.y + 8), 
				new G2Point(rect.x, rect.y + 8));
			joinM.getDrawAttr().setOpacity(0);
			addGdata(gdata, joinM);
			
			G2Line joinW = new G2Line(
				new G2Point(rect.x + rect.width, rect.y + 8), 
				new G2Point(rect.x + rect.width + 10, rect.y + 8));
			joinW.getDrawAttr().setOpacity(0);
			addGdata(gdata, joinW);
				
			if (rightCard == null) {
				createRightCard(family.getWoman());
			}
			rightCard.ox = (joinW.x2);
			rightCard.oy = (leftCard.getTop());
			List<Object> drawW = rightCard.rendered();
			gdata.addAll(drawW);
			/*
			if (!family.getChildren().isEmpty()) {
				G2Line joinC = new G2Line(
					new G2Point(rect.x + 8, rect.y + 16), 
					new G2Point(rect.x + 8, rightCard.getBottom() + 10));
				addGdata(gdata, joinC);
			}
			*/
		}
		return gdata;
	}
	
}
